<?php
namespace Portal\Controller;
use Common\Controller\HomebaseController;

class ReController extends HomebaseController {
	public function showRe(){
		$Re=M('re');
		$Lesson=M('lesson');
		$count=$Re->where($where)->count();
		$page=$this->page($count,10);
		$re=$Re
		->where($where)
		->order('subtime')
		->limit($page->firstRow , $page->listRows)
		->select();
		for($i=0;$i<count($re);$i++){
			$where['lid']=$re[$i]['lid'];
			$le[$i]=$Lesson->where($where)->find();
			$re[$i]['subtime']=date('Y-m-d',$re[$i]['subtime']);
			$re[$i]['le']=$le[$i];
		}
		//dump($re);
		//die();
		$this->assign('re',$re)
		->assign("page", $page->show('Admin'));
		$this->display(':showRe');
	}
		//发送短信功能测试（取消预约后给排队的人发送预约成功的消息）
	public function sendmsg(){
		$msgreid=262;
		$this->send($msgreid);
		echo "hello,it's ok!";
		}
	public function send($msgreid){
		vendor('alidayuSendMsgSDK.TopSdk');
		$Reserve= M('reserve');
		$Member = M('member');
		$Lesson = M('lesson');
		$appkey = '23468650';
		$secret = '5feaf57ca580c21b9c214e3c62a3c10d';
		//配置短息内容
		$where['reid']=$msgreid;
		$where1['uid']=$Reserve->where($where)->getField('uid');
		$where2['lid']=$Reserve->where($where)->getField('lid');
		$memberinfo=$Member->where($where1)->find();
		$name=$memberinfo['name'];
		$tel=$memberinfo['tel'];
		$lessoninfo=$Lesson->where($where2)->find();
		$sdate=substr($lessoninfo['sdate'],5,2)."月".substr($lessoninfo['sdate'],8,2)."日";
		$stime=substr($lessoninfo['stime'],0,5);
		$sitename=$lessoninfo['sitename'];
		$lesson=$lessoninfo['lesson'];
		$c = new \TopClient;
		$c->appkey = $appkey;
		$c->secretKey = $secret;
		$req = new \AlibabaAliqinFcSmsNumSendRequest;
		$req->setExtend("123456");
		$req->setSmsType("normal");
		$req->setSmsFreeSignName("如释瑜伽");
		$req->setSmsParam("{\"name\":\"$name\",\"sdate\":\"$sdate\",\"stime\":\"$stime\",\"lesson\":\"$lesson\"}");
		$req->setRecNum("$tel");
		$req->setSmsTemplateCode("SMS_17955003");
		$resp = $c->execute($req);
	}
}